package com.gui.mianshiya.service.impl;

import com.gui.mianshiya.service.AiQuestionService;
import io.github.lnyocly.ai4j.platform.openai.chat.entity.ChatCompletion;
import io.github.lnyocly.ai4j.platform.openai.chat.entity.ChatCompletionResponse;
import io.github.lnyocly.ai4j.platform.openai.chat.entity.ChatMessage;
import io.github.lnyocly.ai4j.service.IChatService;
import io.github.lnyocly.ai4j.service.PlatformType;
import io.github.lnyocly.ai4j.service.factor.AiService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Title: AiUtils
 * @Author quit
 * @Package com.gui.mianshiya.utils
 * @Date 2025/4/28 19:31
 * @description:
 */
@Service
public class AiQuestionServiceImpl implements AiQuestionService {

    @Resource
    private   AiService aiService;

    public   String getAiQuestion(String question) throws Exception {

        question = question +"     只需要回答问题，描述详情，并建议学者该怎么学习 ";
        IChatService chatService = aiService.getChatService(PlatformType.DEEPSEEK);
        // 构建请求参数
        ChatCompletion chatCompletion = ChatCompletion.builder()
                .model("deepseek-chat")
                .message(ChatMessage.withUser(question))
                .build();

        // 发送对话请求
        ChatCompletionResponse response = chatService.chatCompletion(chatCompletion);
        return response.getChoices().get(0).getMessage().getContent().getText().toString();
    }
}
